package sjtu.ist.warehouse4ws.dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.model.Modelgroup;

public class ModelgroupDaoHibernate extends BaseDaoHibernate<Modelgroup> implements ModelgroupDao{

	public Modelgroup get(Integer id) {
		return (Modelgroup)getHibernateTemplate().get(Modelgroup.class, id);
	}

	public Integer save(Modelgroup modelgroup) {
		getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_EAGER); 
		return (Integer)getHibernateTemplate().save(modelgroup);
	}

	public void update(Modelgroup modelgroup) {
		
		getHibernateTemplate().update(modelgroup);
	}

	public void delete(Integer id) {
		
		getHibernateTemplate().delete(get(id));
	}

	public void delete(Modelgroup modelgroup) {
		
		getHibernateTemplate().delete(modelgroup);
	}

	@Override
	public List<Modelgroup> getAll() {
		// TODO Auto-generated method stub
		return (List<Modelgroup>)getSession().createSQLQuery("select Modelgroup.* from Modelgroup").addEntity(Modelgroup.class).list();
	}

	@Override
	public List<Modelgroup> getDistinctName() {
		// TODO Auto-generated method stub
		return getSession().createSQLQuery("select * from Modelgroup group by groupName").addEntity(Modelgroup.class).list();
		//return getHibernateTemplate().find("from Modelgroup group by groupName");
	}
	
	@Override
	public List<Modelgroup> findByName(String name) {
		// TODO Auto-generated method stub
		return (List<Modelgroup>)getSession().createSQLQuery("select Modelgroup.* from Modelgroup where groupName='"+name+"'").addEntity(Modelgroup.class).list();
	}

//	@Override
//	public List<Modelgroup> findByCompany(String companyId) {
//		// TODO Auto-generated method stub
//		return getHibernateTemplate().find("from Modelgroup m where m.companyId ='"+companyId+"'");
//	}
}
